package com.shop.page.controller;



import com.shop.common.pojo.RD;
import com.shop.common.pojo.SpManager;
import com.shop.page.service.UserFeign;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/page")
@CrossOrigin
public class PageController {
   @Resource
   private UserFeign userFeign;
    @RequestMapping("/getData/{id}")
    public SpManager findDataById(@PathVariable Integer id) {
        SpManager goods=userFeign.query(id);
        System.out.println(goods);
        return goods;
    }
        @RequestMapping("/getPort")
    public String getProductServerPort() {
            System.out.println("这是9100");
        return userFeign.findServerPort();
    }

    @GetMapping("/users")
    public RD findAll(@RequestParam(value = "query",defaultValue = "") String query,@RequestParam(value = "pagenum",defaultValue = "1") int pagenum,@RequestParam(value = "pagesize",defaultValue = "2") int pagesize) {
        return userFeign.findAll(query,pagenum,pagesize);
    }
    @PostMapping("/users")
    public RD addUser(SpManager spManager)
    {
        System.out.println(spManager);
        return userFeign.addUser(spManager);
    }
    @PutMapping("/users/{uId}/state/{type}")
    public RD updateUserState(@PathVariable int uId,@PathVariable int type)
    {
        return userFeign.updateUserState(uId,type);
    }
    @GetMapping("/users/{id}")
    public RD selectUserById(@PathVariable int id)
    {
        return userFeign.selectUserById(id);
    }
    @PutMapping("/users/{id}")
    public RD updateUser(@PathVariable int id,@RequestBody SpManager spManager)
    {
        return userFeign.updateUser(id,spManager);
    }
    @DeleteMapping("/users/{id}")
    public RD deleteUser(@PathVariable int id)
    {
        return userFeign.deleteUser(id);
    }
}
